﻿using ERP.ERPSystem.HumanResources;
using ERP.ERPSystem.HumanResources.Dto;
using ERP.Team.HumanResources;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ERP.Web.Controllers.HumanResources
{
    /// <summary>
    /// 入职审核控制器
    /// </summary>
    [Route("[controller]/[action]")]
    public class OnboardingReviewController : Controller
    {
        private readonly IOnboardingReviewServices _onboardingReviewServices;

        /// <summary>
        /// 构造函数，通过依赖注入获取入职审核服务
        /// </summary>
        /// <param name="onboardingReviewServices">入职审核服务实例</param>
        public OnboardingReviewController(IOnboardingReviewServices onboardingReviewServices)
        {
            _onboardingReviewServices = onboardingReviewServices;
        }
        
        /// <summary>
        /// 返回 "添加入职审核" 的视图页面
        /// </summary>
        /// <returns>AddAuditview.cshtml 视图</returns>
        [HttpGet]
        public IActionResult AddAuditview()
        {
            return View();
        }

        /// <summary>
        /// (API) 添加入职审核记录
        /// </summary>
        /// <param name="onboardingReviewDto">从请求体中绑定的审核信息DTO</param>
        /// <returns>新创建记录的ID</returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<int> AddAuditOnboardingReview([FromBody] OnboardingReviewDto onboardingReviewDto)
        {
            var i = await _onboardingReviewServices.AddAuditOnboardingReview(onboardingReviewDto);
            return i;
        }

        /// <summary>
        /// 返回 "入职审核列表" 的主视图页面
        /// </summary>
        /// <returns>Auditview.cshtml 视图</returns>
        [HttpGet]
        public IActionResult Auditview()
        {
            return View();
        }

        /// <summary>
        /// (API) 查询审核列表
        /// </summary>
        /// <param name="personName">(筛选条件) 申请人姓名</param>
        /// <param name="interviewPeople">(筛选条件) 面试官姓名</param>
        /// <returns>符合条件的入职审核实体列表</returns>
        [HttpGet]
        public async Task<List<OnboardingReview>> ShowAuditOnboardingReview(string? personName, string? interviewPeople)
        {
            return await _onboardingReviewServices.ShowAuditOnboardingReview(personName, interviewPeople);
        }
    }
}
